package org.jeecg.modules.sg.service.impl;

import org.jeecg.modules.sg.entity.SgBerth;
import org.jeecg.modules.sg.entity.SgChangeRoom;
import org.jeecg.modules.sg.entity.SgOutRoom;
import org.jeecg.modules.sg.entity.SgPerson;
import org.jeecg.modules.sg.mapper.SgOutRoomMapper;
import org.jeecg.modules.sg.service.ISgBerthService;
import org.jeecg.modules.sg.service.ISgOutRoomService;
import org.jeecg.modules.sg.service.ISgPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Description: 退宿申请单
 * @Author: jeecg-boot
 * @Date:   2022-09-29
 * @Version: V1.0
 */
@Service
public class SgOutRoomServiceImpl extends ServiceImpl<SgOutRoomMapper, SgOutRoom> implements ISgOutRoomService {
    @Autowired
    public ISgPersonService iSgPersonService;
    @Autowired
    public ISgBerthService iSgBerthService;

    @Override
    @Transactional
    public void audSgInRooms(String[] ids) {
        for (String id:ids){
            SgOutRoom sgOutRoom=this.getById(id);
            if("ysh".equals(sgOutRoom.getStatus())){
            }else{
                sgOutRoom.setStatus("ysh");
                sgOutRoom.setAudDate(new Date());//审核时间
                this.updateById(sgOutRoom);
                SgPerson sgPerson=iSgPersonService.getById(sgOutRoom.getPresonId());
                //构建补充SgPerson的数据
                sgOutRoom.buildPerson(sgPerson);
                iSgPersonService.updateById(sgPerson);
                //修改床位的状态
                SgBerth sgBerth=iSgBerthService.getById(sgOutRoom.getBerthId());
                sgBerth.setPersonId(null);
                iSgBerthService.updateById(sgBerth);
            }
        }
    }
}
